Skip to content

[type layout] usize and isize have the same size and alignment#2200

Open
joshlf wants to merge 1 commit intorust-lang:masterfrom
joshlf:patch-8
Open

[type layout] usize and isize have the same size and alignment#2200
joshlf wants to merge 1 commit intorust-lang:masterfrom
joshlf:patch-8

Conversation

@joshlf
Copy link
Contributor

@joshlf joshlf commented Mar 4, 2026

Everybody assumes this to be true, and I assume it was intended to be guaranteed to be true.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Mar 4, 2026
@joshlf
Copy link
Contributor Author

joshlf commented Mar 4, 2026

r? @RalfJung

@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2026

Failed to set assignee to RalfJung: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@joshlf
Copy link
Contributor Author

joshlf commented Mar 4, 2026

r? @ehuss

@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. labels Mar 10, 2026
@traviscross
Copy link
Contributor

Makes sense. It is a new language guarantee, though, so...

@rfcbot fcp merge lang

@traviscross traviscross added T-lang Relevant to the language team. I-lang-easy-decision The decision needed by lang is conjectured to be easy; this dose not imply nomination. and removed I-lang-easy-decision The decision needed by lang is conjectured to be easy; this dose not imply nomination. labels Mar 10, 2026
@traviscross

This comment was marked as duplicate.

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Mar 10, 2026

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@scottmcm
Copy link
Member

Is there an equivalent statement about alignment that iN and uN have the same alignment in the reference?

@joshlf
Copy link
Contributor Author

joshlf commented Mar 10, 2026

Is there an equivalent statement about alignment that iN and uN have the same alignment in the reference?

No. I'd be happy to relax this to just saying that sizes are equal, which is really what I (personally) care about.

@scottmcm
Copy link
Member

TBH I think that both are obvious things to provide. Was just seeing that we have the size equality guarantees for uN & iN (via the table specifying their exact sizes) so this is blatantly obvious for size. Was just thinking that if the alignment equality was worth guaranteeing for usize & isize then it's probably worth doing for the others too.

(I have no strong feelings about the best way to do that. If you wanted to just just make this be size that's fine; if you wanted to just open another PR to also give the alignment guarantee for the specific-sized integer types that'd also be fine.)

@joshlf
Copy link
Contributor Author

joshlf commented Mar 11, 2026

Oh I'm totally happy guaranteeing both. From my perspective, more guarantees is always better. But I didn't know if there was some reason that the language might want to keep this option open – maybe theres' some weird opsem thing I don't know about (cc @RalfJung) or some weird architecture on which these two have different alignments. For example, there's that MSVC thing where its allocator allocates 8-byte-aligned values at 4 byte alignment – maybe there's some architecture where LLVM lowers signed values differently than unsigned ones or something weird like that.

@joshlf
Copy link
Contributor Author

joshlf commented Mar 11, 2026

If we end up deciding we're okay with alignment, I'd also be happy to update this PR to guarantee alignment equality b/w all uN and iN, not just usize and isize.

@RalfJung
Copy link
Member

RalfJung commented Mar 11, 2026

No weird opsem thing I am aware of (LLVM doesn't even know the sign of our integers most of the time). But the potential for weird architectures is of course unbounded and that's not my expertise. That said, AFAIK the LLVM data layout string cannot even represent sign-dependent alignment so it seems unlikely that LLVM could work on a target where integers with the same size and different sign have different alignment. Cc @nikic

@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@joshtriplett
Copy link
Member

Is there an equivalent statement about alignment that iN and uN have the same alignment in the reference?

I think there should be.

@nikic
Copy link
Contributor

nikic commented Mar 11, 2026

No weird opsem thing I am aware of (LLVM doesn't even know the sign of our integers most of the time). But the potential for weird architectures is of course unbounded and that's not my expertise. That said, AFAIK the LLVM data layout string cannot even represent sign-dependent alignment so it seems unlikely that LLVM could work on a target where integers with the same size and different sign have different alignment. Cc @nikic

Yes, LLVM data layout is sign independent. Technically, Clang could use different alignment based on signedness, in much the same way __int128 and _BitInt(128) have different alignment despite being the same i128 type on the LLVM IR level. I'm not aware of any targets where this would be the case though, and it seems pretty unlikely to me. Platform ABIs are crazy, but not that crazy.

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

god I hope this is not controversial

@tmandry
Copy link
Member

tmandry commented Mar 11, 2026

@rfcbot reviewed

@traviscross traviscross removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Mar 11, 2026
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed P-lang-drag-1 Lang team prioritization drag level 1. labels Mar 11, 2026
@scottmcm
Copy link
Member

From the lang meeting: please also make another PR to add the ∀N, alignof(iN) == alignof(uN) rule.

(Rather than needing to change this one that's already in FCP.)

@joshlf
Copy link
Contributor Author

joshlf commented Mar 11, 2026

Put up #2205 to guarantee ∀N, alignof(iN) == alignof(uN).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge final-comment-period I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-review Status: The marked PR is awaiting review from a maintainer T-lang Relevant to the language team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.